from tkinter import * from tkinter import filedialog import tkinter.messagebox from tkinter.ttk import * import string import codecs import os import webbrowser root = Tk() root.title("MuSi program 1.5") root.iconbitmap("MuSiProgramIcon.ico") root.minsize(360, 710) razlika = 0 # ****************************** MENIJSKA VRSTICA ****************************** def izbor(): global nfoDatoteka nfoDatoteka = filedialog.askopenfile(filetypes = (("NFO files", "*.NFO"), ("All files", "*.*"))) nfoDatotekaPath = nfoDatoteka.name global nfoDatotekaCodecs nfoDatotekaCodecs = codecs.open(nfoDatotekaPath, encoding = "utf-8") vstavljanje() def vstavljanje(): for i in range(22): nfoDatotekaCodecs.readline() readLine23 = nfoDatotekaCodecs.readline() newReadLine23v2 = readLine23.strip() entry_naslov.insert(0, newReadLine23v2) for i in range(7): nfoDatotekaCodecs.readline() readLine31 = nfoDatotekaCodecs.readline() newReadLine31 = readLine31.replace(" Artist.............: ", "") newReadLine31v2 = newReadLine31.strip() entry_avtor.insert(0, newReadLine31v2) readLine32 = nfoDatotekaCodecs.readline() newReadLine32 = readLine32.replace(" Album..............: ", "") newReadLine32v2 = newReadLine32.strip() entry_album.insert(0, newReadLine32v2) readLine33 = nfoDatotekaCodecs.readline() newReadLine33 = readLine33.replace(" Year...............: ", "") newReadLine33v2 = newReadLine33.strip() entry_leto.insert(0, newReadLine33v2) readLine34 = nfoDatotekaCodecs.readline() newReadLine34 = readLine34.replace(" Genre..............: ", "") newReadLine34v2 = newReadLine34.strip() entry_zvrst.insert(0, newReadLine34v2) for i in range(3): nfoDatotekaCodecs.readline() readLine38 = nfoDatotekaCodecs.readline() newReadLine38 = readLine38.replace(" Music Format.......: ", "") newReadLine38v2 = newReadLine38.strip() entry_formatGlasbe.insert(0, newReadLine38v2) nfoDatotekaCodecs.readline() readLine40 = nfoDatotekaCodecs.readline() newReadLine40 = readLine40.replace(" Playing Time.......: ", "") newReadLine40v2 = newReadLine40.strip() entry_casIgranja.insert(0, newReadLine40v2) readLine41 = nfoDatotekaCodecs.readline() newReadLine41 = readLine41.replace(" Total Size.........: ", "") newReadLine41v2 = newReadLine41.strip() entry_skupnaVelikost.insert(0, newReadLine41v2) for i in range(14): nfoDatotekaCodecs.readline() readLine56 = nfoDatotekaCodecs.readline() newReadLine56 = readLine56.replace(" Quality............: ", "") newReadLine56v2 = newReadLine56.strip() entry_kvaliteta.insert(0, newReadLine56v2) readLine57 = nfoDatotekaCodecs.readline() newReadLine57 = readLine57.replace(" Channels...........: ", "") newReadLine57v2 = newReadLine57.strip() entry_kanali.insert(0, newReadLine57v2) for i in range(9): nfoDatotekaCodecs.readline() dolociRazlika() def dolociRazlika(): stevec = 0 for line in nfoDatotekaCodecs: stevec += 1 global razlika razlika = stevec - 23 vstavljanjeTracklist() def vstavljanjeTracklist(): nfoDatoteka.close() nfoDatotekaPath = nfoDatoteka.name nfoDatoteka2 = open(nfoDatotekaPath, "r") nfoDatoteka2Codecs = codecs.open(nfoDatotekaPath, encoding = "utf-8") for i in range(66): nfoDatoteka2Codecs.readline() stevko = float(razlika) pozicija = float(1) if razlika < 10: for i in range(razlika): tracklistReadLines = nfoDatoteka2Codecs.readline() newTracklistReadLines = tracklistReadLines.strip() text.insert(INSERT, newTracklistReadLines) text.insert(INSERT, "\n") if razlika >= 10 and razlika < 100: for i in range(9): stevko = float(razlika) tracklistReadLines = nfoDatoteka2Codecs.readline() newTracklistReadLines = tracklistReadLines.strip() text.insert(INSERT, newTracklistReadLines) text.insert(INSERT, "\n") for i in range(razlika - 9): stevko = float(razlika) tracklistReadLines = nfoDatoteka2Codecs.readline() newTracklistReadLines = tracklistReadLines.strip() text.insert(INSERT, newTracklistReadLines) text.insert(INSERT, "\n") if razlika >= 100 and razlika < 1000: for i in range(9): stevko = float(razlika) tracklistReadLines = nfoDatoteka2Codecs.readline() newTracklistReadLines = tracklistReadLines.strip() text.insert(INSERT, newTracklistReadLines) text.insert(INSERT, "\n") for i in range(90): stevko = float(razlika) tracklistReadLines = nfoDatoteka2Codecs.readline() newTracklistReadLines = tracklistReadLines.strip() text.insert(INSERT, newTracklistReadLines) text.insert(INSERT, "\n") for i in range(razlika - 99): stevko = float(razlika) tracklistReadLines = nfoDatoteka2Codecs.readline() newTracklistReadLines = tracklistReadLines.strip() text.insert(INSERT, newTracklistReadLines) text.insert(INSERT, "\n") def clearInput(): entry_naslov.delete(0, END) entry_avtor.delete(0, END) entry_album.delete(0, END) entry_zvrst.delete(0, END) entry_leto.delete(0, END) entry_formatGlasbe.delete(0, END) entry_kvaliteta.delete(0, END) entry_kanali.delete(0, END) entry_casIgranja.delete(0, END) entry_skupnaVelikost.delete(0, END) text.delete(1.0, END) entry_YouTubeLink.delete(0, END) entry_artwork.delete(0, END) class izhod0: def izhod1(): root.destroy() def izhod2(): odgovor = tkinter.messagebox.askquestion("Exit", "Are you sure you want to exit the program?") if odgovor == "yes": izhod0.izhod1() def nadVsemi(): root.wm_attributes("-topmost", 1) def zazeniUpdater(): os.startfile("MuSi.Updater.exe") def odpriURL(): webbrowser.open("http://musi.partis.si/viewtopic.php?f=103&t=625") meni = Menu(root) root.config(menu = meni) podMeniFile = Menu(meni) meni.add_cascade(label = "File", menu = podMeniFile) podMeniFile.add_command(label = "Open a file", command = izbor) podMeniFile.add_command(label = "Clear input", command = clearInput) podMeniFile.add_separator() podMeniFile.add_command(label = "Exit", command = izhod0.izhod2) podMeniOptions = Menu(meni) meni.add_cascade(label = "Options", menu = podMeniOptions) podMeniOptions.add_command(label = "Always on top", command = nadVsemi) podMeniHelp = Menu(meni) meni.add_cascade(label = "Help", menu = podMeniHelp) podMeniHelp.add_command(label = "Check for updates", command = zazeniUpdater) podMeniHelp.add_command(label = "Instructions", command = odpriURL) #******************************************************************************* frame1 = Frame() frame1.grid() frame2 = Frame() frame2.grid() frame3 = Frame() frame3.grid() label_naslov = Label(frame1, text = "Naslov") entry_naslov = Entry(frame1, width = 42) label_naslov.grid(sticky = E) entry_naslov.grid(row = 0, column = 1) entry_naslov.focus_set() label_avtor = Label(frame1, text = "Artist") entry_avtor = Entry(frame1, width = 42) label_avtor.grid(sticky = E, row = 1, column = 0) entry_avtor.grid(row = 1, column = 1) label_album = Label(frame1, text = "Album") entry_album = Entry(frame1, width = 42) label_album.grid(sticky = E) entry_album.grid(row = 2, column = 1) label_zvrst = Label(frame1, text = "Genre") entry_zvrst = Entry(frame1, width = 42) label_zvrst.grid(sticky = E) entry_zvrst.grid(row = 3, column = 1) label_leto = Label(frame1, text = "Year") entry_leto = Entry(frame1, width = 42) label_leto.grid(sticky = E) entry_leto.grid(row = 4, column = 1) label_formatGlasbe = Label(frame1, text = "Music Format") entry_formatGlasbe = Entry(frame1, width = 42) label_formatGlasbe.grid(row = 0, column = 2, sticky = E, pady = 2) entry_formatGlasbe.grid(row = 0, column = 3) label_kvaliteta = Label(frame1, text = "Quality") entry_kvaliteta = Entry(frame1, width = 42) label_kvaliteta.grid(row = 1, column = 2, sticky = E, pady = 2) entry_kvaliteta.grid(row = 1, column = 3) label_kanali = Label(frame1, text = "Channels") entry_kanali = Entry(frame1, width = 42) label_kanali.grid(row = 2, column = 2, sticky = E, pady = 2) entry_kanali.grid(row = 2, column = 3) label_casIgranja = Label(frame1, text = "Playing Time") entry_casIgranja = Entry(frame1, width = 42) label_casIgranja.grid(row = 3, column = 2, sticky = E, pady = 2) entry_casIgranja.grid(row = 3, column = 3) label_skupnaVelikost = Label(frame1, text = "Total Size") entry_skupnaVelikost = Entry(frame1, width = 42) label_skupnaVelikost.grid(row = 4, column = 2, sticky = E, pady = 2) entry_skupnaVelikost.grid(row = 4, column = 3) label_YouTubeLink = Label(frame3, text = "YouTube link") entry_YouTubeLink = Entry(frame3, width = 94) label_YouTubeLink.grid(row = 6, sticky = E) entry_YouTubeLink.grid(row = 6, column = 1, sticky = E, pady = 2) label_artwork = Label(frame3, text = "Artwork") entry_artwork = Entry(frame3, width = 94) label_artwork.grid(row = 7, sticky = E) entry_artwork.grid(row = 7, column = 1, sticky = E, pady = 2) label_MuSiLogo = Label(frame3, text = "MuSi logo") entry_MuSiLogo = Entry(frame3, width = 94) label_MuSiLogo.grid(row = 8, sticky = E) entry_MuSiLogo.grid(row = 8, column = 1, sticky = E, pady = 2) def makeActive1(): jeAliNi = jeChecked1.get() if jeAliNi == 1: entry_MuSiLogo.configure(state='normal') if jeAliNi == 0: entry_MuSiLogo.configure(state='disabled') jeChecked1 = IntVar() checkButton1 = Checkbutton(frame3, command = makeActive1, variable = jeChecked1) checkButton1.grid(row = 8, column = 2) label_logo = Label(frame3, text = "Logo") entry_logo = Entry(frame3, width = 94) label_logo.grid(row = 9, sticky = E) entry_logo.grid(row = 9, column = 1, sticky = E, pady = 2) def makeActive2(): jeAliNi = jeChecked2.get() if jeAliNi == 1: entry_logo.configure(state='normal') if jeAliNi == 0: entry_logo.configure(state='disabled') jeChecked2 = IntVar() checkButton2 = Checkbutton(frame3, command = makeActive2, variable = jeChecked2) checkButton2.grid(row = 9, column = 2) label_slika = Label(frame3, text = "Image") entry_slika = Entry(frame3, width = 94) label_slika.grid(row = 10, sticky = E) entry_slika.grid(row = 10, column = 1, sticky = E, pady = 2) def makeActive3(): jeAliNi = jeChecked3.get() if jeAliNi == 1: entry_slika.configure(state='normal') if jeAliNi == 0: entry_slika.configure(state='disabled') jeChecked3 = IntVar() checkButton3 = Checkbutton(frame3, command = makeActive3, variable = jeChecked3) checkButton3.grid(row = 10, column = 2) links = open("links.txt", mode = "r") a = links.readline() av2 = a.strip() entry_MuSiLogo.insert(0, av2) entry_MuSiLogo.configure(state = "disabled") b = links.readline() bv2 = b.strip() entry_logo.insert(0, bv2) entry_logo.configure(state = "disabled") c = links.readline() cv2 = c.strip() entry_slika.insert(0, cv2) entry_slika.configure(state = "disabled") links.close() # ****************************** FUNKCIJA GUMBA ****************************** def generateAndCopy(): root.clipboard_clear() naslovZacetekBB = "[color=#cc0000][size=18]" naslovKonecBB = "[/size][/color]" naslovVneseno = entry_naslov.get() if len(naslovVneseno) > 0: line1 = "[color=#cc0000][size=18]%s[/size][/color]\n \n" % (naslovVneseno) root.clipboard_append(line1) artworkZacetekBB = "[img]" artworkKonecBB = "[/img]" artworkVneseno = entry_artwork.get() if len(artworkVneseno) > 0: line2 = "[img]%s[/img]\n \n" % (artworkVneseno) root.clipboard_append(line2) root.clipboard_append("[color=blue][b][u]Info:[/u][/b][/color]\n \n") avtorVneseno = entry_avtor.get() if len(avtorVneseno) > 0: avtorClipboard = "[color=black][b]Artist:[/b][/color]", str(avtorVneseno) line3 = "[color=black][b]Artist:[/b][/color] %s \n" % (avtorVneseno) root.clipboard_append(line3) albumVneseno = entry_album.get() if len(albumVneseno) > 0: stringtest = "[color=black][b]Album:[/b][/color]" albumClipboard = stringtest, albumVneseno line4 = "[color=black][b]Album:[/b][/color] %s \n" % (albumVneseno) root.clipboard_append(line4) zvrstVneseno = entry_zvrst.get() if len(zvrstVneseno) > 0: line5 = "[color=black][b]Genre:[/b][/color] %s \n" % (zvrstVneseno) root.clipboard_append(line5) letoVneseno = entry_leto.get() if len(letoVneseno) > 0: line6 = "[color=black][b]Year:[/b][/color] %s \n \n" % (letoVneseno) root.clipboard_append(line6) formatGlasbeVneseno = entry_formatGlasbe.get() if len(formatGlasbeVneseno) > 0: line7 = "[color=black][b]Music Format:[/b][/color] %s \n" % (formatGlasbeVneseno) root.clipboard_append(line7) kvalitetaVneseno = entry_kvaliteta.get() if len(kvalitetaVneseno) > 0: line8 = "[color=black][b]Quality:[/b][/color] %s \n" % (kvalitetaVneseno) root.clipboard_append(line8) kanaliVneseno = entry_kanali.get() if len(kanaliVneseno) > 0: line9 = "[color=black][b]Channels:[/b][/color] %s \n \n" % (kanaliVneseno) root.clipboard_append(line9) casIgranjaVneseno = entry_casIgranja.get() if len(casIgranjaVneseno) > 0: line10 = "[color=black][b]Playing Time:[/b][/color] %s \n" % (casIgranjaVneseno) root.clipboard_append(line10) skupnaVelikostVneseno = entry_skupnaVelikost.get() if len(skupnaVelikostVneseno) > 0: line11 = "[color=black][b]Total Size:[/b][/color] %s \n \n" % (skupnaVelikostVneseno) root.clipboard_append(line11) steviloVrstic2 = int(text.index("end-1c").split(".")[0]) if steviloVrstic2 > 0: lineTracklist = "[color=blue][b][u]Tracklist:[/u][/b][/color] \n \n" root.clipboard_append(lineTracklist) lineTracklistColorZacetek = "[color=black]" root.clipboard_append(lineTracklistColorZacetek) if steviloVrstic2 < 10 and steviloVrstic2 != 0: stevnik1 = 1.0 stevnik2 = 1.2 stevnik3 = 1.3 stevnik4 = 2.0 stevnik5 = 1 for i in range(razlika): tracklistVneseno = text.get(stevnik1, stevnik2) tracklistVneseno2 = text.get(stevnik3, stevnik4) spremeljivka = "[b]%s[/b] %s" % (tracklistVneseno, tracklistVneseno2) stevnik1 += 1 stevnik2 += 1 stevnik3 += 1 stevnik4 += 1 root.clipboard_append(spremeljivka) lineTracklistColorKonec = "[/color]" root.clipboard_append(lineTracklistColorKonec) if steviloVrstic2 >= 10 and steviloVrstic2 <= 100 and steviloVrstic2 != 0: stevnik1 = 1.0 stevnik2 = 1.2 stevnik3 = 1.3 stevnik4 = 2.0 for i in range(9): tracklistVneseno = text.get(stevnik1, stevnik2) tracklistVneseno2 = text.get(stevnik3, stevnik4) spremeljivka = "[b]%s[/b] %s" % (tracklistVneseno, tracklistVneseno2) stevnik1 += 1 stevnik2 += 1 stevnik3 += 1 stevnik4 += 1 root.clipboard_append(spremeljivka) stevnik1 = 10.0 stevnik2 = 10.3 stevnik3 = 10.4 stevnik4 = 11.0 for i in range(razlika - 9): tracklistVneseno = text.get(stevnik1, stevnik2) tracklistVneseno2 = text.get(stevnik3, stevnik4) spremeljivka = "[b]%s[/b] %s" % (tracklistVneseno, tracklistVneseno2) stevnik1 += 1 stevnik2 += 1 stevnik3 += 1 stevnik4 += 1 root.clipboard_append(spremeljivka) lineTracklistColorKonec = "[/color]" root.clipboard_append(lineTracklistColorKonec) if steviloVrstic2 >= 100 and steviloVrstic2 < 1000 and steviloVrstic2 != 0: stevnik1 = 1.0 stevnik2 = 1.3 stevnik3 = 1.4 stevnik4 = 2.0 for i in range(9): tracklistVneseno = text.get(stevnik1, stevnik2) tracklistVneseno2 = text.get(stevnik3, stevnik4) spremeljivka = "[b]%s[/b] %s" % (tracklistVneseno, tracklistVneseno2) stevnik1 += 1 stevnik2 += 1 stevnik3 += 1 stevnik4 += 1 root.clipboard_append(spremeljivka) stevnik1 = 10.0 stevnik2 = 10.3 stevnik3 = 10.4 stevnik4 = 11.0 for i in range(90): tracklistVneseno = text.get(stevnik1, stevnik2) tracklistVneseno2 = text.get(stevnik3, stevnik4) spremeljivka = "[b]%s[/b] %s" % (tracklistVneseno, tracklistVneseno2) stevnik1 += 1 stevnik2 += 1 stevnik3 += 1 stevnik4 += 1 root.clipboard_append(spremeljivka) stevnik1 = 100.0 stevnik2 = 100.4 stevnik3 = 100.5 stevnik4 = 101.0 for i in range(razlika - 99): tracklistVneseno = text.get(stevnik1, stevnik2) tracklistVneseno2 = text.get(stevnik3, stevnik4) spremeljivka = "[b]%s[/b] %s" % (tracklistVneseno, tracklistVneseno2) stevnik1 += 1 stevnik2 += 1 stevnik3 += 1 stevnik4 += 1 root.clipboard_append(spremeljivka) lineTracklistColorKonec = "[/color]" root.clipboard_append(lineTracklistColorKonec) YouTubeLinkVneseno = entry_YouTubeLink.get() if len(YouTubeLinkVneseno) > 0: line13 = "\n \n[youtube]%s[/youtube] \n \n" % (YouTubeLinkVneseno) root.clipboard_append(line13) NFOandUploadByLine = "\n \n[b][color=red]Več v NFO – ju[/b][/color]\n" root.clipboard_append(NFOandUploadByLine) artworkVneseno = entry_artwork.get() if len(artworkVneseno) > 0: line14 = "[img]%s[/img] \n \n" % (artworkVneseno) root.clipboard_append(line14) MuSiLogoVneseno = entry_MuSiLogo.get() if len(MuSiLogoVneseno) > 0: uploadByLine = "[b][color=green]Upload by[/b][/color]\n \n" root.clipboard_append(uploadByLine) line15 = "[img]%s[/img] \n \n" % (MuSiLogoVneseno) root.clipboard_append(line15) logoVneseno = entry_logo.get() if len(logoVneseno) > 0: line16 = "[img]%s[/img] \n \n" % (logoVneseno) root.clipboard_append(line16) slikaVneseno = entry_slika.get() if len(slikaVneseno) > 0: line17 = "[img]%s[/img] \n \n" % (slikaVneseno) root.clipboard_append(line17) links2 = open("links.txt", mode = "w") zaMuSiLogoVneseno = "%s \n" % (MuSiLogoVneseno) links2.write(zaMuSiLogoVneseno) zaLogoVneseno = "%s \n" % (logoVneseno) links2.write(zaLogoVneseno) zaSlikaVneseno = "%s \n" % (slikaVneseno) links2.write(zaSlikaVneseno) #********************************************************************************************************* labelFrame = LabelFrame(frame2, text = "Tracklist") labelFrame.grid() text = Text(labelFrame, wrap = NONE) text.grid() yScrollBar = Scrollbar(labelFrame) yScrollBar.grid(column = 1, row = 0, sticky = "NS") xScrollBar = Scrollbar(labelFrame, orient = HORIZONTAL) xScrollBar.grid(column = 0, row = 1, sticky = "WE") text.config(yscrollcommand = yScrollBar.set) text.config(xscrollcommand = xScrollBar.set) yScrollBar.config(command = text.yview) xScrollBar.config(command = text.xview) #********************************************************************************************************* frame4Button = Frame() frame4Button.grid() button = Button(frame4Button, text = "Generate and copy", command = generateAndCopy, width = 106) button.grid(ipady = 7, pady = 5) frame5Bottom = Frame() frame5Bottom.grid() MuSiLabel = Label(frame5Bottom, text = "MuSi") MuSiLabel.grid() avtorPrograma = Label(frame5Bottom, text = "Anže Hren © 2015") avtorPrograma.grid() root.mainloop()